
public class MaximalRectangle {

}
/*Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
 * 
 * 
 */
class Solution {
    int max = 0;
    char [][] m;
    
    public int maximalRectangle(char[][] matrix) {
        m = matrix;
        
        for(int i =0  ; i < m.length ; i ++)
        {
            for(int j = 0 ; j < m[0].length ; j++)
            {
                checkR(i, j);
            }
        }
        return max;
    }
    
    public void checkR(int r, int c)
    {
        int rowMax = m.length - r;
        int colMax = m[0].length - c;
        
        int temp = 0;
        
        for(int i = 0 ; i < rowMax ; i++) // row
        {
            for(int j = 0 ; j < colMax ; j++) // col
            {
                if(m[r+i][c+j] == '0')
                {
                    colMax = j;
                }
                else
                {
                    temp = (i+1)*(j+1);
                    if(temp > max) max = temp;
                }
            }
        }
    }
}